//
//  TLLaunchAniController.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/10/12.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//

#import "TLLaunchAniController.h"
#import "AppDelegate.h"

@implementation TLLaunchAniController

- (id)initWithGifPath:(NSString *)path{
    self = [super init];
    if(self)
    {
        self.gifPath = path;
        
        self.animImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [TLDeviceManger deviceScreenSize].width, [TLDeviceManger deviceScreenSize].height)];
        self.animImageView.layer.contents = (id)[UIImage imageNamed:@"Intrduction"];
        //set gif path
        [self.animImageView setGifPath:path];
        //add animation view
        [self.view addSubview:self.animImageView];
    }
    
    return self;
}

- (void)viewDidLoad{
    
}

//animation start
- (void)startAnimation{
    [self.animImageView startGIF:^(float aniDuration) {
        NSLog(@"动画结束");
        dispatch_async(dispatch_get_main_queue(), ^{
            [self stopAnimation];
           [UIView animateWithDuration:2.f animations:^{
                 [self.animImageView setAlpha:0.0f];
            } completion:^(BOOL finished) {
                [self.animImageView removeFromSuperview];
                
                [AppDelegate changeRootViewController];
            }];
            
        });

    }];
}
//animation reset
- (void)stopAnimation{
    [self.animImageView stopGIF];
}
@end
